package com.wink.admin.common.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 响应code
 *
 * @author xw
 * @date 2020/10/27 13:56
 */
@Getter
@RequiredArgsConstructor
public enum ResultCode {

    /**
     * 响应code
     */
    SUCCESS(200, "请求成功"),
    FAIL(500, "服务器繁忙，请稍后再试！"),
    NULL_FAIL(400, "参数为null异常！"),
    REPEAT_SUBMIT_FAIL(401, "业务异常！"),
    AUTH_FAIL(403, "过期或无效的token！"),
    // 参数验证
    PARAM_MISS(10002, "参数错误"),
    PARAM_TYPE_ERROR(10003, "参数类型错误"),
    PARAM_VALID_ERROR(10004, "参数校验异常"),
    PARAM_BIND_ERROR(10005, "参数绑定异常"),
    // 接口不存在
    NOT_FOUND(10006, "未找到控制器"),
    METHOD_NOT_SUPPORTED(10007, "请求方法不支持"),
    // 服务降级相关
    SERVICE_DEGRADE(11000, "访问的资源(接口)降级"),
    // 授权相关
    NOT_LOGIN(12000, "未登录"),
    UNAUTHORIZED(12001, "没有权限");

    final int code;
    final String msg;

    public static ResultCode valueBy(int code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.code == code) {
                return resultCode;
            }
        }
        return null;
    }

}
